package com.wizinno.android.urineflow.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.wizinno.android.urineflow.R;
import com.wizinno.android.urineflow.constant.CommonControl;
import com.wizinno.android.urineflow.constant.FragmentNoConstant;
import com.wizinno.android.urineflow.util.FileUtil;
import com.wizinno.android.urineflow.util.ToastUtil;

public class SystemFragment extends BaseFragment {

    private EditText et_device_company;
    private Button btn_setting_submit;

    public SystemFragment() {
        setNo(FragmentNoConstant.SETTING_SYSTEM);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        et_device_company = view.findViewById(R.id.et_device_company);
        btn_setting_submit = view.findViewById(R.id.btn_setting_submit);

        et_device_company.setText(CommonControl.INSTANCE.DEVICE_COMPANY);
        btn_setting_submit.setOnClickListener(new SystemClickListener());
    }

    @Override
    protected void initData() {
    }

    class SystemClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            String deviceCompany = et_device_company.getText().toString();
            FileUtil.writeDeviceCompany(deviceCompany);
            CommonControl.INSTANCE.DEVICE_COMPANY = deviceCompany;
            ToastUtil.showLong(CommonControl.INSTANCE.settingBaseActivity,"修改成功");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_system, container, false);
    }
}